import { GTextFormat } from "../../common/GTextFormat";
import { FontUtil } from "../../common/font/FontUtil";
import { Global } from "../../../com/gengine/global/Global";
import { ObjectPool } from "../../../com/gengine/utils/pools/ObjectPool";
import { ParamsConst } from "../../common/global/ParamsConst";
import { ProxyType } from "../../common/global/ProxyType";
import { FilterConst } from "../../component/gconst/FilterConst";
import { LayerManager } from "./LayerManager";
import { TweenMax } from "../../../com/greensock/TweenMax";
import { EffectManager } from "./EffectManager";
type int = number;
//class MsgPlotShowImpl
    
    export  class MsgPlotShowImpl /* flash.display.Sprite */
    {
        constructor()
        {
            
            this._infoTxtFormat = new GTextFormat(FontUtil.xingkaiName, 30, 16777215, false);
            this._infoTxtFormatTW = new GTextFormat(FontUtil.songtiName, 30, 16777215, false);
            this._msgList = [];
            this._infoTxtFormat.leading = 1;
            this._infoTxtFormat.align = flash.text.TextFormatAlign.LEFT;
            this._infoTxtFormatTW.leading = 1;
            this._infoTxtFormatTW.align = flash.text.TextFormatAlign.LEFT;
            mouseEnabled = false;
            mouseChildren = false;
            return;
        }

        /* internal  */onMaskClickHandler(): void
        {
            var loc1=NaN;
            if (this._lastClickTime == 0) 
            {
                this._lastClickTime = flash.utils.getTimer();
                return;
            }
            else 
            {
                loc1 = flash.utils.getTimer();
                if (loc1 - this._lastClickTime > 400) 
                {
                    this._lastClickTime = loc1;
                    return;
                }
                this._lastClickTime = loc1;
            }
            var loc2=this._step;
            switch (loc2) 
            {
                case 1:
                {
                    this._inTimeOut = 0.1;
                    break;
                }
                case 2:
                {
                    flash.utils.clearTimeout(this._timerKey);
                    this.playHideEffect2();
                    break;
                }
                case 3:
                {
                    this._outTimeOut2 = 0.1;
                    break;
                }
            }
            return;
        }

        public showMsg(arg1: string, arg2: Function): void
        {
            var loc1=null;
            var loc4=null;
            var loc5=null;
            this.hideMsg();
            this._inTimeOut = 1;
            this._outTimeOut = 0.2;
            this._outTimeOut2 = 0.5;
            this.alpha = 1;
            this._endCallBack = arg2;
            loc1 = arg1.split("|");
            var loc2=0;
            var loc3=loc1.length;
            var loc6;
            if ((loc6 = Global.stage.stageWidth / 2 + loc1.length * this._lineWidth) > Global.stage.stageWidth - 320) 
            {
                loc6 = Global.stage.stageWidth - 320;
            }
            while (loc2 < loc3) 
            {
                loc5 = ObjectPool.getObject(flash.text.TextField);
                if (ParamsConst.instance.proxyType != ProxyType.TW) 
                {
                    loc5.defaultTextFormat = this._infoTxtFormat;
                }
                else 
                {
                    loc5.defaultTextFormat = this._infoTxtFormatTW;
                }
                loc5.width = this._lineWidth;
                loc5.autoSize = flash.text.TextFieldAutoSize.LEFT;
                loc5.multiline = true;
                loc5.wordWrap = true;
                loc5.mouseEnabled = false;
                loc5.filters = [FilterConst.plotShowFilter2, FilterConst.plotShowFilter, FilterConst.sceneDesFilter];
                loc5.x = loc6 - loc2 * this._lineWidth;
                loc5.y = 0;
                loc5.text = loc1[loc2];
                this._msgList.push(loc5);
                ++loc2;
            }
            LayerManager.highestLayer.addChild(this);
            this.stageReseze();
            this.playShowEffect();
            return;
        }

        /* internal  */playShowEffect(): void
        {
            var loc1=null;
            if (this._msgList.length > 0) 
            {
                loc1 = this._msgList.shift() as Object /* flash.text.TextField */;
                loc1.alpha = 0;
                this.addChild(loc1);
                this._inTween = TweenMax.to(loc1, this._inTimeOut, {"alpha": 1, "onComplete": this.playShowEffect});
                this._step = 1;
            }
            else 
            {
                this._timerKey = flash.utils.setTimeout(this.playHideEffect2, 3000);
                this._step = 2;
            }
            return;
        }

        /* internal  */playHideEffect(arg1: Boolean=false): void
        {
            var loc1=null;
            this._step = 3;
            if (this.numChildren > 0) 
            {
                loc1 = this.getChildAt(0) as Object /* flash.text.TextField */;
                if (!arg1) 
                {
                    loc1.text = "";
                    loc1.filters = null;
                    this.removeChild(loc1);
                    ObjectPool.disposeObject(loc1, flash.text.TextField);
                    if (this.numChildren > 0) 
                    {
                        loc1 = this.getChildAt(0) as Object /* flash.text.TextField */;
                    }
                }
                if (loc1.parent) 
                {
                    this._outTween = TweenMax.to(loc1, this._outTimeOut, {"alpha": 0, "onComplete": this.playHideEffect});
                }
                else 
                {
                    this.hideEffectEnd();
                }
            }
            else 
            {
                this.hideEffectEnd();
            }
            return;
        }

        /* internal  */playHideEffect2(): void
        {
            this._step = 3;
            this._outTween = TweenMax.to(this, this._outTimeOut2, {"alpha": 0, "onComplete": this.hideEffectEnd});
            return;
        }

        /* internal  */hideEffectEnd(): void
        {
            this._step = 0;
            if (this._endCallBack != null) 
            {
                this._endCallBack();
            }
            this.hideMsg();
            return;
        }

        public stageReseze(): void
        {
            if (parent != null) 
            {
                this.y = (Global.stage.stageHeight - this.height) / 2;
                if (y > 70) 
                {
                    y = 70;
                }
            }
            return;
        }

        public hideMsg(): void
        {
            var loc1=null;
            this._lastClickTime = 0;
            this._step = 0;
            this._endCallBack = null;
            EffectManager.hideUIMask();
            if (this.parent) 
            {
                this.parent.removeChild(this);
            }
            if (this._inTween && this._inTween.active) 
            {
                this._inTween.kill();
            }
            if (this._outTween && this._outTween.active) 
            {
                this._outTween.kill();
            }
            flash.utils.clearTimeout(this._timerKey);
            while (this.numChildren > 0) 
            {
                loc1 = this.removeChildAt(0) as Object /* flash.text.TextField */;
                loc1.filters = null;
                loc1.text = "";
                ObjectPool.disposeObject(loc1, flash.text.TextField);
            }
            while (this._msgList.length > 0) 
            {
                loc1 = this._msgList.shift() as Object /* flash.text.TextField */;
                loc1.filters = null;
                loc1.text = "";
                ObjectPool.disposeObject(loc1, flash.text.TextField);
            }
            return;
        }

        public /* override */ get height(): number
        {
            var loc3=0;
            var loc4=null;
            var loc1=1;
            var loc2=numChildren;
            while (loc1 < loc2) 
            {
                if ((loc4 = getChildAt(loc1) as Object /* flash.text.TextField */) && loc4.textHeight > loc3) 
                {
                    loc3 = loc4.textHeight;
                }
                ++loc1;
            }
            loc1 = 0;
            loc2 = this._msgList.length;
            while (loc1 < loc2) 
            {
                if ((loc4 = this._msgList[loc1] as Object /* flash.text.TextField */) && loc4.textHeight > loc3) 
                {
                    loc3 = loc4.textHeight;
                }
                ++loc1;
            }
            return loc3;
        }

        public /* override */ get width(): number
        {
            return (numChildren + this._msgList.length) * this._lineWidth;
        }

        /* internal */ /* var */_infoTxtFormat: Object /* flash.text.TextFormat */;

        /* internal */ /* var */_infoTxtFormatTW: Object /* flash.text.TextFormat */;

        /* internal */ /* var */_inTween: TweenMax;

        /* internal */ /* var */_outTween: TweenMax;

        /* internal */ /* var */_timerKey: uint;

        /* internal */ /* var */_lineWidth: int=38;

        /* internal */ /* var */_inTimeOut: number=1;

        /* internal */ /* var */_outTimeOut: number=0.2;

        /* internal */ /* var */_outTimeOut2: number=0.5;

        /* internal */ /* var */_step: int;

        /* internal */ /* var */_msgList: Array<any>;

        /* internal */ /* var */_endCallBack: Function;

        /* internal */ /* var */_lastClickTime: number=0;
    }
